﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;

public partial class Register : System.Web.UI.PageEx
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!DalEx.DbSystemEx.ReadBaoMingState())
        {
            Response.Redirect("404.aspx");
        }
        if (!Page.IsPostBack)
        {
            string strLink = "<li><a href=\"{0}\">{1}</a></li>";
            StringBuilder sbMenuLinks = new StringBuilder();
            if (UserType == 1 && UserId > 0)
            {
                sbMenuLinks.Append(string.Format(strLink, new object[] { "MemberCenter.aspx", "会员中心" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "UserInfos.aspx", "我的资料" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "ModifyPwd.aspx", "修改密码" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "MyBaoMing.aspx", "我的报名表" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "MyYiGongBaoMing.aspx", "义工报名表" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "MyHomeEventBaoMing.aspx", "家园活动报名表" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "Logout.aspx", "退出系统" }));
            }
            else
            {
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "会员中心" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "我的资料" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "修改密码" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "我的报名表" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "义工报名表" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "家园活动报名表" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "退出系统" }));
            }
            litMenuLinks.Text = sbMenuLinks.ToString();
        }
    }
    protected void btnRegister_Click(object sender, EventArgs e)
    {
        short sSex = 0;
        string strUserName = SqlHelper.String(txtUserName.Text);
        string strUserPwd = SqlHelper.String(txtUserPwd.Text);
        string strConfirmPwd = SqlHelper.String(txtConfirmPwd.Text);
        string strFirstName = SqlHelper.String(txtFirstName.Text);
        string strLastName = SqlHelper.String(txtLastName.Text);
        short.TryParse(rblSex.SelectedValue, out sSex);
        string strTel = SqlHelper.String(txtTel.Text);
        string strAddress = SqlHelper.String(txtAddress.Text);
        string strEmail = SqlHelper.String(txtEmail.Text);

        if (strUserPwd.Equals(strConfirmPwd))
        {
            Model.DbUsers dbUser = new Model.DbUsers();
            dbUser.UserName = strUserName;
            dbUser.UserPwd = strUserPwd;// SqlHelper.MD5(strUserPwd, 32);
            dbUser.FirstName = strFirstName;
            dbUser.LastName = strLastName;
            dbUser.Tel = strTel;
            dbUser.Address = strAddress;
            dbUser.Sex = sSex;
            dbUser.AddTime = DateTime.Now;
            dbUser.LastLoginTime = SqlHelper.MinDate;
            dbUser.TotalCost = 0;
            dbUser.LoginTimes = 0;
            dbUser.Email = strEmail;
            dbUser.Status = 1;
            dbUser.LastIP = "127.0.0.1";

            int iUserId = 0;
            string strResult = string.Empty;
            if (DalEx.DbUserDalEx.Insert(dbUser, ref strResult, ref iUserId)>0)
            {
                UserType = 1;
                UserId = iUserId;
                UserName = dbUser.UserName;
                MessageBox1(strResult, "UserLogin.aspx");
            }
            else
            {
                MessageBox(strResult);
            }
        }
        else
        {
            MessageBox("抱歉，您两次输入的密码不一致！");
            return;
        }
    }
}
